package web.binder;

import app.entity.Point;
import org.springframework.format.Formatter;

import java.text.ParseException;
import java.util.Locale;

public class PointFormatter implements Formatter<Point> {
    @Override
    public Point parse(String text, Locale locale) throws ParseException {
        Point point=null;
        if(text.contains(",")){
            point =new Point();
            int x=Integer.parseInt(text.split(",")[0]);
            int y=Integer.parseInt(text.split(",")[1]);
            point.setX(x);
            point.setY(y);
        }
        return point;
    }

    @Override
    public String print(Point object, Locale locale) {
        if(object==null)return null;

        return object.toString();
    }
}
